<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./templates/templateMenu.xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="content">
        <script type="text/javascript"> 
            function confirmFunction() {
                 updateConfirm.jq.click();
            }
        </script>
        <p:panel header="Serie de Recibos">
            <h:panelGrid columns="3" id="frmSerie">
                <h:outputText value="Nombre de la Serie:"/>
                <p:inputText id="txtSerie" 
                             required="true" 
                             requiredMessage="Requerido"
                             value="#{serieBean.serie.vcSerie}"/>
                <p:message for="txtSerie"/>

                <h:outputText value="Último ingresado:"/>
                <p:spinner id="txtUltimo" 
                           required="true" 
                           min="000000000000"
                           max="999999999999" 
                           stepFactor="1"
                           requiredMessage="Requerido"
                           value="#{serieBean.serie.nuUltimoValor}"/>
                <p:message for="txtUltimo"/>
            </h:panelGrid>

            <h:panelGrid style="width: 100%">
                <p:toolbar>
                    <p:toolbarGroup align="left">      
                        <p:commandButton value="Nuevo"
                                         title="Nuevo"
                                         action="#{serieBean.nuevo}"
                                         process="@this"
                                         update="frmSerie"
                                         image="ui-icon-document"/>
                        <p:commandButton value="Guardar" 
                                         action="#{serieBean.crear}"
                                         title="Guardar" 
                                         process="@this frmSerie" 
                                         oncomplete="confirmFunction();"
                                         update="frmSerie dtSerie msg"
                                         image="ui-icon-disk">                                                                                       
                        </p:commandButton> 
                    </p:toolbarGroup>
                </p:toolbar>
            </h:panelGrid>

            <p:dataTable id="dtSerie" 
                         widgetVar="dtSerie"                                        
                         rows="10" 
                         paginator="true" 
                         var="varSerie" 
                         value="#{serieBean.series}"
                         onRowEditUpdate="msg">

                <f:facet name="header">  
                    <h:panelGrid style="width: 200px;" columnClasses="alignLeft,alignLeft,alignLeft" columns="3">
                        <h:outputText value="Buscar: " />  
                        <p:inputText  id="globalFilter" onkeyup="dtNivel.filter()" style="width:150px" />  
                    </h:panelGrid> 
                </f:facet>  

                <p:column filterBy="#{varSerie.vcSerie}" 
                          filterStyle="display: none" 
                          headerText="Serie de Recibo" 
                          style="text-align: center;">
                    <h:outputText value="#{varSerie.vcSerie}"/>
                </p:column>

                <p:column filterBy="#{varSerie.nuUltimoValor}" 
                          filterStyle="display: none" 
                          style="text-align:center;"
                          headerText="Ultimo Numero de la Serie">
                    <h:outputText value="#{varSerie.nuUltimoValor}"/>
                </p:column> 

                <p:column style="text-align: center; width: 75px;" headerText="Acciones" >  
                    <f:facet name="header"/>
                    <p:commandButton  image="ui-icon-pencil" 
                                      title="Modificar Serie"
                                      action="#{serieBean.modificar}"
                                      update="frmSerie"
                                      oncomplete="confirmFunction();"
                                      process="@this">  
                        <f:setPropertyActionListener value="#{varSerie}" target="#{serieBean.selectedSerie}" />
                    </p:commandButton> 
                    <p:commandButton  image="ui-icon-trash"
                                      title="Eliminar Serie"
                                      oncomplete="confirmation.show()"
                                      update="confirm" 
                                      process="@this">  
                        <f:setPropertyActionListener value="#{varSerie}" target="#{serieBean.selectedSerie}" />
                    </p:commandButton>  
                </p:column> 
            </p:dataTable>
        </p:panel>
        <p:confirmDialog message="Desea eliminar el registro?" 
                         width="400"   
                         header="Confirm" 
                         severity="alert" 
                         widgetVar="confirmation" 
                         modal="true">  
            <p:outputPanel id="confirm">
                <h:panelGrid>
                    <h:outputText  value="Serie: #{serieBean.selectedSerie.vcSerie}"/>
                    <h:panelGrid columns="2">
                        <p:commandButton value="Si" 
                                         update="dtSerie msg"
                                         action="#{serieBean.eliminar}" 
                                         oncomplete="confirmation.hide(); confirmFunction(); dtSerie.filter()" 
                                         process="@this">
                            <f:param name="idSerie" 
                                     value="#{serieBean.selectedSerie.idSerie}"/>
                        </p:commandButton>
                        <p:commandButton value="No" 
                                         onclick="confirmation.hide()" 
                                         type="button" />    
                    </h:panelGrid>
                </h:panelGrid>
            </p:outputPanel>
        </p:confirmDialog>

        <p:commandButton style="visibility: hidden" 
                         widgetVar="updateConfirm"
                         oncomplete="dtSerie.filter()" 
                         update="dtSerie msg"/>
    </ui:define>

</ui:composition>
